package com.vim.common.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Bean
    public ObjectMapper objectMapper() {
        return new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    }

    /**
     * 静态资源配置
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //文档
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");

        //主模块
        registry.addResourceHandler("/views/**").addResourceLocations("classpath:/public/views/");
        registry.addResourceHandler("/plugins/**").addResourceLocations("classpath:/public/plugins/");

        //子模块
        registry.addResourceHandler("/module/views/**").addResourceLocations("classpath:/public/module/views/");
        registry.addResourceHandler("/module/plugins/**").addResourceLocations("classpath:/public/module/plugins/");
    }

}